package com.example.hashcode;

import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

/**
 * hashcode
 *
 * @author qingyan 2021-10-08
 */
public class HashCodeTest {
    public static void main(String[] args) {
        String str = "dasd123ddasd23dcHKHGFHDSKKA";
        System.out.println(str.hashCode());
        int h = 0;
        for (int i = 0; i < str.length(); i++) {
            h = h * 31 + str.charAt(i);
        }
        System.out.println(h);
        System.out.println(Objects.hashCode(str));
        System.out.println(System.identityHashCode(str));
        int a = 1000;
        System.out.println(Integer.hashCode(a));
        System.out.println(System.identityHashCode(a));
        System.out.println(Objects.hashCode(a));
    }
    @Test
    public void weifei(){
        System.out.println(7^8);
    }

    @Test
    public void linkedHashMap(){
        Map<Integer, Integer> map = new LinkedHashMap<>();
        map.put(1, 2);
        map.put(12, 2);
        map.put(21, 2);
        map.put(5, 2);
        map.put(12, 5);
        map.forEach((k, v) -> System.out.println(k + "-" + v));
    }

}
